<?php $auth=0; ?>
<?php include 'lib/includes.php'; ?>
<?php include 'partials/header_menu.php'; ?>
<script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="jquery/jquery-ui-1.11.2.custom/jquery-ui.min.js"></script>

<?php
$nomm='';$prixm='';$ids='';
if(isset($_POST['nomm'])&&isset($_POST['prixm'])&&isset($_POST['idsoc'])) 
{     
		$nomm=$db->quote($_POST['nomm']);
		$prixm=$db->quote($_POST['prixm']);
		$idsoc=(int)$_POST['idsoc'];
		if(isset($_GET['id'])){
			
			$id=$db->quote($_GET['id']);
		
		$db->query("update medicament set medicamentNom=$nomm,medicamentPrix=$prixm,societeId=$idsoc where medicamentId=$id");
		header('Location: /prescription/drug.php');
		die();
		}
		else
		{ 
			$db->query("insert into medicament (medicamentNom,medicamentPrix,societeId)  SELECT $nomm,$prixm,societeId from societe where societeId=$idsoc");
			header('Location: /prescription/drug.php');
			die();
		}
}


if(isset($_GET['id'])){
		$id=$db->quote($_GET['id']);
		$select=$db->query("select * from medicament inner join societe on medicament.societeId=societe.societeId where medicamentId=$id");
	    $_POST=$select->fetch();
		$nomm=$db->quote($_POST['medicamentNom']);
		$prixm=$db->quote($_POST['medicamentPrix']);
		$ids=$db->quote($_POST['societeId']);
	}
?>
<form class="form-horizontal" method="post">
<br>
<h3><span class="titre">&nbsp;&nbsp;Détails du médicament</span></h3>
<br>
   <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">Nom du médicament:</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="nomm" value="<?php echo str_replace("'","",$nomm) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">Prix du médicament:</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="prixm" value="<?php echo str_replace("'","",$prixm) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">ID du société :</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="idsoc" value="<?php echo str_replace("'","",$ids) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-4 col-sm-10">
      <button type="submit" class="btn btn-success">valider</button>
	  <a href="drug.php" class="btn btn-default">annuler</a>
    </div>
  </div>
</form>
<?php include 'partials/footer.php'; ?>
